import 'package:flutter/material.dart';

enum Position { top, center, bottom }

showToast(
  BuildContext context,
  String message, {
  Position position = Position.bottom,
  int duration = 2,
}) {
  final overlay = Overlay.of(context);
  final overlayEntry = OverlayEntry(
    builder:
        (context) => Positioned(
          top:
              position == Position.top
                  ? MediaQuery.of(context).size.height * 0.12
                  : null,
          bottom:
              position == Position.bottom
                  ? MediaQuery.of(context).size.height * 0.12 - 56
                  : null,
          left: position == Position.center ? null : 0,
          right: position == Position.center ? null : 0,
          child: Material(
            color: Colors.transparent,
            child: Center(
              child: Container(
                padding: EdgeInsets.symmetric(horizontal: 24, vertical: 8),
                decoration: BoxDecoration(
                  color: Color.fromRGBO(0, 0, 0, 0.7),
                  borderRadius: BorderRadius.circular(8),
                ),
                child: Text(
                  message,
                  style: TextStyle(color: Colors.white, fontSize: 14),
                ),
              ),
            ),
          ),
        ),
  );

  overlay.insert(overlayEntry);
  Future.delayed(Duration(seconds: duration), () => overlayEntry.remove());
}
